package com.sm.service;

import java.util.List;

import com.sm.model.ShopCar;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sm.dao.ShopCarMapper;

/**
 *	购物车Service层
 * @author 60915
 *
 */
@Service
public class ShopCarService {
	
	@Autowired
	private ShopCarMapper shopCarMapper;
	
	/**
	 *	插入购物车数据
	 * @param record	购物车实体类
	 * @return
	 */
	public int insertSelective(ShopCar record) {
		return shopCarMapper.insertSelective(record);
	}
	
	/**
	 *	根据用户的id查询购物车中的数据
	 * @return
	 */
	public List<ShopCar> selectShopCarByUserId(Integer userId){
		return shopCarMapper.selectShopCarByUserId(userId);
	}
	
	/**
	 *	通话商品id，用户id，和商品规格查询购物车中是否存在这件商品，
	 * @param userId	用户id
	 * @param goodsId	商品id
	 * @param format	商品规格
	 * @return
	 */
	public ShopCar selectShopCarIfBeing(Integer userId, Integer goodsId, String format) {
		return shopCarMapper.selectShopCarIfBeing(userId, goodsId, format);
	}
	
	/**
	 *	更新购物车中的商品数据。
	 * @param record	购物车数据。
	 * @return
	 */
	public int updateByPrimaryKeySelective(ShopCar record) {
		return shopCarMapper.updateByPrimaryKeySelective(record);
	}
	
	/**
	 *	通过购物车id查询购物车中的数据
	 * @param shopCarId		购物车id
	 * @return
	 */
	public ShopCar selectByPrimaryKey(Integer shopCarId) {
		return shopCarMapper.selectByPrimaryKey(shopCarId);
	}
	
	/**
     *	根据用户查询用户的购物车数量
     * @param userId	用户id
     * @return
     */
	public int selectShopCarNumber(Integer userId) {
		return shopCarMapper.selectShopCarNumber(userId);
	}
	
	/**
	 *	删除购物车
	 * @param shopCarId
	 * @return
	 */
	public int deleteByPrimaryKey(Integer shopCarId) {
		return shopCarMapper.deleteByPrimaryKey(shopCarId);
	}
	
	/**
	 *	清空购物车
	 * @param userId	用户id
	 * @return
	 */
	public int cleanShopCar(Integer userId) {
		return shopCarMapper.cleanShopCar(userId);
	}
	
	/**
	 *	通过用户id和购物车id查询购物车数据
	 * @param userId	用户id
	 * @param shopCarId	购物车id
	 * @return
	 */
	public ShopCar selectShopCarByGoodsId(Integer userId, Integer shopCarId) {
		return shopCarMapper.selectShopCarByGoodsId(userId, shopCarId);
		
	}
	
	

}
